﻿#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int evalRPN(vector<string>& tokens)
    {
        stack<int> st;
        for (auto e : tokens)
        {
            if (e == "+" || e == "-" || e == "*" || e == "/")
            {
                int right = st.top();
                st.pop();

                int left = st.top();
                st.pop();

                if (e == "+")
                    st.push(left + right);
                else if (e == "-")
                    st.push(left - right);
                else if (e == "*")
                    st.push(left * right);
                else
                    st.push(left / right);
            }
            else
            {
                st.push(stoi(e));
            }
        }
        return st.top();
    }
};

